import { Entity, Column, CreateDateColumn, PrimaryColumn, OneToMany, ManyToOne, JoinColumn } from 'typeorm';
import { ActionLogOta } from './actionLogOta.entity';
import { Firmware } from './firmware.entity';

@Entity('ota_task')
export class OtaTask {
  @PrimaryColumn({ type: 'varchar', length: 255 })
  id: string;

  @Column({ type: 'varchar', length: 255, nullable: true })
  firmwareid: string;

  @Column({ type: 'varchar', length: 255, nullable: true })
  firmwareid_1: string;





  
  @ManyToOne(() => Firmware, firmware => firmware.otaTasks, {
    nullable: true,
    onDelete: 'SET NULL'
  })

  @JoinColumn({ name: 'firmwareid' })
  firmware: Firmware; // 与 Firmware 表关联

  @ManyToOne(() => Firmware, firmware => firmware.otaTasks, {
    nullable: true,
    onDelete: 'SET NULL'
  })


  @JoinColumn({ name: 'firmwareid_1' })
  firmware1: Firmware; // 与 Firmware 

  @Column({ type: 'varchar', length: 255 })
  gw_mac: string; // 网关 MAC 地址

  @Column({ type: 'text' }) // 使用 text 类型
  wb_mac: string; // 手环 MAC 地址

  @Column({ type: 'boolean', default: false })
  full: boolean;

  @Column({ type: 'boolean', default: false })
  gw_full: boolean;

  @Column({ type: 'boolean', default: false })
  wb_full: boolean;

  @Column({ type: 'boolean', default: false })
  force: boolean;

  @Column({ type: 'boolean', default: false })
  remain: boolean;

  @Column({ type: 'varchar', length: 255 })
  path: string;

  @Column({ type: 'varchar', length: 255 })
  updateMode: string; // 升级方式

  @CreateDateColumn({ type: 'timestamp', nullable: true })
  time: Date; // 操作时间

  @CreateDateColumn({ type: 'timestamp', nullable: true })
  updateTime: Date; // 修改时间

  @OneToMany(() => ActionLogOta, actionLog => actionLog.task)
  actionLogs: ActionLogOta[]; // 与 ActionLogOta 表关联

  @Column({ type: 'int', nullable: true })
  duration: number; // 手环升级时长

  @Column({ type: 'int', nullable: true })
  wb_count: number; // 手环升级数量

  @Column({ type: 'boolean', default: false })
  deleted: boolean;
  
}
